package by.bsu.rfe.belianko.euniversity.controller.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import by.bsu.rfe.belianko.euniversity.constants.LoggerMessages;
import by.bsu.rfe.belianko.euniversity.constants.PageNames;

/**
 * Performs the exit from system.
 * 
 * @author Vitali_Belianko
 * 
 */

public class LogoutCommand implements Command {

	private static final String SESSION_INVALIDATE = "Session invalidate!";
	private static final Logger LOGGER = Logger.getLogger(LogoutCommand.class);

	/**
	 * Logs out the user from the system.
	 * 
	 * @param request
	 * 
	 * @return login page
	 */
	@Override
	public String execute(HttpServletRequest request) {

		LOGGER.debug(LoggerMessages.STARTED_COMMAND);

		HttpSession session = request.getSession();
		session.invalidate();

		LOGGER.debug(SESSION_INVALIDATE);

		LOGGER.debug(LoggerMessages.FINISHED_COMMAND);

		return PageNames.LOGIN_PAGE;
	}

}
